package org.linlinjava.litemall.db.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * litemall充电消费
 *
 * @author yliyun
 * @date 2022/10/27
 */
@Data
@TableName("litemall_recharge_consumption")
public class LitemallRechargeConsumption {
    /**
     * 被删除
     */
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    /**
     * 不删除
     */
    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    /**
     * id
     */
    @TableId
    private Integer id;

    /**
     * 用户id
     */
    private Integer userId;

    /**
     * 订单id
     */
    private Integer orderId;

    /**
     * 移动
     */
    private String mobile;

    /**
     * 用户名
     */
    private String username;

    /**
     * 用户级
     */
    private Byte userLevel;

    /**
     * 可用数量
     */
    private BigDecimal availableAmount;

    /**
     * 点
     */
    private BigDecimal points;

    /**
     * 类型
     */
    private Byte type;

    /**
     * 量
     */
    private BigDecimal amount;

    /**
     * 删除
     */
    private Boolean deleted;

    /**
     * 添加时间
     */
    private LocalDateTime addTime;

    /**
     * 添加用户id
     */
    private Integer addUserId;

    /**
     * 订单来源
     */
    private Byte orderSource;

    private Integer payType;


    /**
     * 订单sn
     */
    @TableField(exist = false)
    private String orderSn;
    /**
     * 订单类型
     */
    @TableField(exist = false)
    private Byte orderType;
    /**
     * 备注消息
     */
    @TableField(exist = false)
    private String message;



    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        userId("user_id", "userId", "INTEGER", false),
        orderId("order_id", "orderId", "INTEGER", false),
        mobile("mobile", "mobile", "VARCHAR", false),
        username("username", "username", "VARCHAR", false),
        userLevel("user_level", "userLevel", "TINYINT", false),
        availableAmount("available_amount", "availableAmount", "DECIMAL", false),
        points("points", "points", "DECIMAL", false),
        type("type", "type", "TINYINT", true),
        amount("amount", "amount", "DECIMAL", false),
        deleted("deleted", "deleted", "BIT", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        addUserId("add_user_id", "addUserId", "INTEGER", false),
        orderSource("order_source", "orderSource", "TINYINT", false);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}